<template>
  <div class="filter-list">
    <a-collapse
      :activeKey="activeKey"
      :bordered="false"
      expand-icon-position="right"
      @change="onChange"
    >
      <a-collapse-panel key="1" :header="header">
        <span slot="extra">{{ tip }}</span>
        <slot></slot>
      </a-collapse-panel>
    </a-collapse>
  </div>
</template>

<script>
export default {
  name: "SBreadcrumb",
  props: {
    header: {
      type: String,
      default: "筛选列表",
      required: false
    },
    opend: {
      type: Boolean,
      required: false,
      default: true
    }
  },
  data() {
    return {
      activeKey: "",
      keys: []
    };
  },
  watch: {
    opend: {
      immediate: true,
      handler(value) {
        if (value) {
          this.activeKey = "1";
          this.keys = ["1"];
        } else {
          this.activeKey = "";
          this.keys = [];
        }
      }
    }
  },
  computed: {
    tip() {
      return this.keys.length ? "收起筛选项" : "展开筛选项";
    }
  },
  methods: {
    onChange(key) {
      this.keys = key;
      this.$emit("changOpend", !!this.keys.length);
    }
  }
};
</script>
